<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\SectionsRequest;
use Illuminate\Http\Request;
use App\Admin\Subject;
use App\Admin\Sections;
use App\Admin\Question;

class SectionsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Subject $id)
    {

        $data=Sections::where('subject',$id->id)->paginate(10);
        return view('admin.sections_index',compact('data','id'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Subject $id)
    {
        return view('admin.sections_create',compact('id'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(SectionsRequest $request)
    {
        $data=$request->only('name','order','subject');
        return Sections::create($data) ? '1':'0';
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Sections $sections)
    {
        return  view('admin.sections_edit',compact('sections'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(SectionsRequest $request, Sections $sections)
    {
        $data=$request->only('name','subject','order');
        return  $sections->update($data) ? '1' :'0';
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Sections $sections)
    {
        return $sections->delete() ? '1' : '0';
        //
    }
}
